﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Input;
using Events;
using MessageBox=System.Windows.MessageBox;

namespace ViewModel
{
    /// <summary>
    /// Base ViewModel application class. It relies on the Model, but also 
    /// on some basic features, like displaying messages.
    /// </summary>
    public class ApplicationViewModel : ViewModelBase
    {
        /// <summary>
        /// The Model instance
        /// </summary>
        internal static Model.Model model;

        /// <summary>
        /// The model accessor. When calling the getModel getter 
        /// it will always return the same instance. If needed another, 
        /// use the setter.
        /// </summary>
        protected Model.Model getModel
        {
            get
            {
                if (model == null)
                {
                    model = new Model.Model();
                    model.OnAppMessageReceived += DisplayAppMessage;
                }

                return model;
            }
            set { model = value; }
        }

        private String appMessage;
        public String AppMessage
        {
            get { return appMessage; }
            set 
            { 
                appMessage = value;
                OnPropertyChanged("AppMessage");
            }
        }

        public void DisplayAppMessage(object sender, AppMessageEventArgs e)
        {
            this.AppMessage = e.Message;
            System.Windows.Forms.MessageBox.Show(e.Message, "KIM - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        public ICommand Message;
    }
}
